const Local = window.localStorage;
const Session = window.sessionStorage;

export function setLocalItem(key, val) {
    Local.setItem(key, JSON.stringify(val));
}
export function getLocalItem(key) {
    let json = Local.getItem(key);
    if (!json || json === 'undefined') {
        return '';
    }
    try {
        return JSON.parse(json);
    } catch (error) {
        return json;
    }
}
export function removeLocalItem(key) {
    Local.removeItem(key);
}
export function clearLocal() {
    Local.clear();
}
export function setSessionItem(key, val) {
    Session.setItem(key, JSON.stringify(val));
}
export function getSessionItem(key) {
    let json = Session.getItem(key);
    if (!json || json === 'undefined') {
        return '';
    }
    try {
        return JSON.parse(json);
    } catch (error) {
        return json;
    }
}
export function removeSessionItem(key) {
    Session.removeItem(key);
}
export function clearSession() {
    Session.clear();
}
